﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ArmaModLauncher
{
    [Serializable]
    class LaunchParameterSettings
    {
        public CheckState ShowScriptErrors { get; set; }
        public CheckState World { get; set; }
        public List<Mod> Mods { get; set; }
        public CheckState NoSplash { get; set; }
        public CheckState UseBeta { get; set; }
        public List<Mod> SpecialMods { get; set; } 

        private string _commandLine;

        public LaunchParameterSettings()
        {
            ShowScriptErrors = CheckState.Unchecked;
            World = CheckState.Unchecked;
            Mods = new List<Mod>();
            NoSplash = CheckState.Unchecked;
            UseBeta = CheckState.Unchecked;
            SpecialMods = new List<Mod>();
        }

        public string CommandLine()
        {
            _commandLine = "";

            if (NoSplash == CheckState.Checked)
                AddCommand("-nosplash");

            if (ShowScriptErrors == CheckState.Checked)
                AddCommand("-showscripterrors");

            if (World == CheckState.Checked)
                AddCommand("-world=empty");

            AddMods();

            return _commandLine;
        }

        public void AddCommand(string command)
        {
            _commandLine += "\"";
            _commandLine += command;
            _commandLine += "\"";
            _commandLine += " ";
        }

        private void AddMods()
        {
            _commandLine += "\"";
            _commandLine += "-mod=";

            foreach(Mod mod in SpecialMods)
            {
                _commandLine += mod.Path;
                _commandLine += ";";
            }

            if (UseBeta == CheckState.Checked)
            {
                _commandLine += "Expansion\\beta;Expansion\\beta\\Expansion";
                _commandLine += ";";
            }

            foreach (Mod mod in Mods)
            {
                if(mod.Selected)
                {
                    _commandLine += mod.Name;
                    _commandLine += ";";
                }
            }

            _commandLine += "\"";
        }
    }
}
